<template>
  <el-dialog title="挂单记录" :visible.sync="visible" width="1200px">
    <div class="el-box">
      <div class="list-box" id="list-box">
        <el-table
          :data="list"
          v-loading="loading"
          stripe
          style="width: 100%"
          header-row-class-name="headcss"
        >
          <el-table-column
            type="selection"
            width="50"
            align="center"
            fixed="left"
          ></el-table-column>
          <el-table-column
            prop="Id"
            label="ID"
            align="center"
          ></el-table-column>
          <el-table-column prop="Addr" label="地址" align="center" width="180">
            <template slot-scope="scope">
              <el-tooltip
                class="item"
                effect="dark"
                :content="scope.row.Addr"
                placement="top"
              >
                <p style="cursor: pointer">{{ addrStr(scope.row.Addr, 8) }}</p>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column
            prop="Email"
            label="邮箱"
            align="center"
            width="190"
          ></el-table-column>
          <el-table-column
            prop="CreateTime"
            label="注册日期"
            align="center"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="UseProfit"
            label="可领取"
            align="center"
            width="100"
          ></el-table-column>
          <el-table-column
            prop="TotalProfit"
            label="总收益"
            align="center"
            width="150"
          ></el-table-column>
          <el-table-column
            prop="Code"
            label="邀请码"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="Father"
            label="邀请关系"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="TeamNum"
            label="团队"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="People"
            label="有效邀请"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="TotalCost"
            label="总花费"
            align="center"
          ></el-table-column>

          <el-table-column prop="BlackFlag" label="黑名单" align="center">
            <template slot-scope="scope">
              {{ scope.row.BlackFlag == 1 ? "黑名单" : "正常" }}
            </template>
          </el-table-column>
          <el-table-column prop="Active" label="激活" align="center">
            <template slot-scope="scope">
              {{ scope.row.Active > 0 ? "已激活" : "未激活" }}
            </template>
          </el-table-column>
          <el-table-column prop="Fueled" label="燃料状态" align="center">
            <template slot-scope="scope">
              {{ scope.row.Fueled == 0 ? "正常" : "欠燃料" }}
            </template>
          </el-table-column>
          <el-table-column
            prop="Steps"
            label="今日步数"
            align="center"
          ></el-table-column>
          <el-table-column prop="is_score," label="认证状态" align="center">
            <template slot-scope="scope">
              {{
                scope.row.VideoCheck == 1001
                  ? "已认证"
                  : scope.row.VideoCheck == 1002
                  ? "审核失败"
                  : "未认证"
              }}
            </template>
          </el-table-column>
          <el-table-column
            prop="StaticRatio"
            label="静态调控比例"
            align="center"
            width="150"
          ></el-table-column>
          <el-table-column
            prop="DynamicRatio"
            label="动态调控比例"
            align="center"
            width="150"
          ></el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            align="center"
            width="336"
          >
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="openAssits(scope.row.Addr)"
                type="text"
                size="medium"
              >
                背包
              </el-button>
              <el-button
                @click.native.prevent="openIncome(scope.row.Addr)"
                type="text"
                size="medium"
              >
                收益
              </el-button>
              <el-button
                @click.native.prevent="openControlModal(scope.row)"
                type="text"
                size="medium"
              >
                收益调控
              </el-button>
              <el-button
                @click.native.prevent="openTeam(scope.row.Email)"
                type="text"
                size="medium"
              >
                团队
              </el-button>
              <el-button
                @click.native.prevent="openBuy(scope.row.Addr, 'sny')"
                type="text"
                size="medium"
              >
                合成
              </el-button>
              <el-button
                @click.native.prevent="openBuy(scope.row.Addr, 'buy')"
                type="text"
                size="medium"
              >
                购买
              </el-button>
              <el-button
                @click.native.prevent="openGd(scope.row.Addr)"
                type="text"
                size="medium"
              >
                挂单
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="page-limit">
        <el-pagination
          @current-change="CurrentChange"
          :current-page="currentPage"
          :page-size="size"
          layout="total, prev, pager, next"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { getUsersBase } from "@/utils/api";
export default {
  props: {
		openAssits:Function,
		openIncome:Function,
		openControlModal:Function,
		openTeam:Function,
		openBuy:Function,
		openGd:Function,
  },
  data() {
    return {
      visible: false,
      list: [],
      loading: false,
      currentPage: 1,
      size: 10,
      total: 0,
      addr: "",
    };
  },
  methods: {
    async _getUsersBase() {
      let params = {
        option: "userbase-set-reward",
        size: this.size,
        page: this.currentPage - 1,
      };
      this.loading = true;
      let { data, response } = await getUsersBase(params);
      let { total, dataList } = data;
      this.loading = false;
      this.total = total;
      this.list = dataList;
    },
    open(addr) {
      this.addr = addr;
      this.visible = true;
      this._getUsersBase();
    },
    CurrentChange(page) {
      this.currentPage = page;
      this._getUsersBase();
    },
    addrStr(str, num) {
      if (str) {
        if (num) {
          return (
            str.substring(0, num) +
            "..." +
            str.substring(str.length - num, str.length)
          );
        } else {
          return (
            str.substring(0, 10) +
            "..." +
            str.substring(str.length - 10, str.length)
          );
        }
      } else {
        return str;
      }
    },
    shoseStr(row) {
      if (row.Level == 0) {
        var beforT = new Date(row.OwnTime).getTime();
        var newT = beforT + 1000 * 60 * 60 * 24 * 30;
        var nowT = new Date().getTime();
        var ts = newT - nowT;
        var day = Math.floor(ts / (1000 * 60 * 60 * 24));
        if (day > 0) {
          return "正常";
        } else {
          return "过期";
        }
      } else {
        if (row.Running == 1) {
          return "跑步中";
        } else {
          if (row.SellState == 0) {
            return "正常";
          } else if (row.SellState == 1) {
            return "挂单中";
          } else if (row.SellState == 2) {
            return "合成中";
          } else if (row.SellState == 3) {
            return "售卖中";
          }
        }
      }
    },
  },
};
</script>

<style scoped lang="scss">
.el-box {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  height: 600px;
}
.list-box {
  flex: 1;
}
.page-limit {
  display: flex;
  width: 100%;
  justify-content: center;
  padding-top: 20px;
}
</style>
<style>
.el-dialog__body {
  padding: 10px 20px 20px !important;
}
</style>
